package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishesService;
import com.sky.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminDishesController")
@RequestMapping("/admin/dish")
public class DishesController {
    @Autowired
    private DishesService dishesService;

    @PutMapping
    public Result updateDishes(@RequestParam DishDTO dishDTO){
        dishesService.updateDishes(dishDTO);
        return Result.success();
    }

    @DeleteMapping
    public Result deleteDishes(@RequestParam List<Integer> ids){
        dishesService.deleteDishes(ids);
        return Result.success();
    }

    @PostMapping
    public Result addDishes(@RequestBody DishDTO dishDTO){
        dishesService.addDishes(dishDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        DishVO dish = dishesService.getById(id);
        return Result.success(dish);
    }

    @GetMapping("/list")
    public Result findByList(@RequestParam Integer categoryId){
        List<DishVO> dish = dishesService.findByList(categoryId);
        return Result.success(dish);
    }

    @GetMapping("/page")
    public Result page(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult = dishesService.page(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status,
                               @RequestParam Integer id){
        dishesService.updateStatus(status,id);
        return Result.success();
    }
}
